/**
 * style.css - 公共样式文件
 * 包含所有页面共用的基础样式：布局、表单、按钮、表格、模态框等
 */

/* ==================== 基础重置 ==================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ==================== 全局样式 ==================== */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    margin: 0;
    padding: 0;
}

/* 阻止背景滚动 - 当模态框打开时添加到 body */
body.modal-open {
    overflow: hidden;
}

/* ==================== 容器布局 ==================== */
.container {
    max-width: 95%;
    width: 100%;
    margin: 16px auto;
    padding: 0 16px;
}

/* 大屏幕下限制最大宽度 */
@media (min-width: 1920px) {
    .container {
        max-width: 1800px;
    }
}

@media (min-width: 1440px) and (max-width: 1919px) {
    .container {
        max-width: 90%;
    }
}

/* ==================== 标题样式 ==================== */
h1, h2, h3 {
    color: #2c3e50;
    margin-bottom: 12px;
}

h1 {
    font-size: 2rem;
    margin-bottom: 16px;
    margin-top: 8px;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

/* ==================== 返回链接 ==================== */
.back-link {
    display: inline-block;
    color: #3498db;
    text-decoration: none;
    margin: 8px 0 16px 0;
    font-size: 16px;
    transition: color 0.2s;
}

.back-link:hover {
    color: #2980b9;
    text-decoration: underline;
}

/* ==================== 内容区块 ==================== */
.section {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin: 16px 0;
}

/* ==================== 表单控件统一样式 ==================== */
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    padding: 10px 12px;
    margin: 8px 0;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    width: 100%;
    max-width: 100%;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* 禁用状态 */
input:disabled,
select:disabled {
    background-color: #f9f9f9;
    color: #999;
    cursor: not-allowed;
}

/* 聚焦高亮 */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* ==================== 标签样式 ==================== */
label {
    display: block;
    margin: 12px 0 6px 0;
    font-weight: 600;
    font-size: 15px;
    color: #2c3e50;
}

/* ==================== 按钮样式 ==================== */
button {
    padding: 10px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    width: 100%;
}

button:hover {
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

/* 主要按钮 */
button:not(.danger):not(.btn-secondary) {
    background: #3498db;
    color: white;
}

button:not(.danger):not(.btn-secondary):hover {
    background: #2980b9;
}

/* 次要按钮 */
button.btn-secondary {
    background: #95a5a6;
    color: white;
}

button.btn-secondary:hover {
    background: #7f8c8d;
}

/* 危险按钮 */
button.danger {
    background: #e74c3c;
    color: white;
}

button.danger:hover {
    background: #c0392b;
}

/* ==================== 按钮组布局 ==================== */
.button-group {
    display: flex;
    gap: 12px;
    margin: 12px 0;
}

.button-group button {
    flex: 1;
}

/* ==================== 表格样式 ==================== */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    background: white;
}

th, td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
}

tr:hover {
    background-color: #f9f9f9;
}

/* 表格响应式容器 */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==================== 状态提示样式 ==================== */
.status {
    display: inline-block;
    margin-top: 8px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 4px;
}

.success {
    color: #27ae60;
    background-color: #d4edda;
}

.error {
    color: #e74c3c;
    background-color: #f8d7da;
}

.loading {
    color: #7f8c8d;
    font-style: italic;
}

/* ==================== 模态框（Modal）基础样式 ==================== */
.modal {
    display: none; /* 默认隐藏 */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: hidden; /* 防止模态框背景滚动 */
    padding: 0;
    /* Flex 布局属性，当 display 改为 flex 时生效 */
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fff;
    margin: 0; /* 去掉 margin，使用 flex 居中 */
    padding: 24px;
    border-radius: 10px;
    width: 90%;
    max-width: 80%;
    max-height: 90vh; /* 限制最大高度为视口的 90% */
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    animation: modalFadeIn 0.3s;
    overflow: auto; /* 内容溢出时可滚动 */
}

/* 模态框淡入动画 */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 模态框关闭按钮 */
.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    line-height: 20px;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: #333;
}

/* 模态框标题栏 */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.modal-title {
    margin: 0;
    font-size: 1.5rem;
    color: #2c3e50;
}

/* 模态框底部按钮 */
.modal-footer {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
}

.modal-footer button {
    width: auto;
    padding: 10px 24px;
}

/* ==================== 响应式设计 ==================== */

/* 平板设备 (768px - 1024px) */
@media (max-width: 1024px) {
    .container {
        max-width: 95%;
    }
}

/* 小屏幕设备 (最大600px) */
@media (max-width: 600px) {
    .container {
        padding: 0 12px;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    h3 {
        font-size: 1.15rem;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
        max-width: 95%;
    }

    /* 按钮组在小屏幕时纵向排列 */
    .button-group {
        flex-direction: column;
    }

    .button-group button {
        width: 100%;
    }

    button,
    input,
    select {
        font-size: 16px; /* 防止iOS自动放大 */
    }

    /* 表格在小屏幕时保持可滚动 */
    table {
        font-size: 14px;
    }

    th, td {
        padding: 8px;
    }

    .modal-title {
        font-size: 1.25rem;
    }
}

/* 极小屏幕 (最大375px) */
@media (max-width: 375px) {
    .container {
        padding: 0 10px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .section {
        padding: 18px;
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    body {
        background: white;
    }

    .modal,
    button,
    .back-link {
        display: none;
    }

    .container {
        max-width: 100%;
    }

    .section {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
